package demo.thread;

public class DemoThread implements Runnable{
	private String threadName;
	private Integer sizeLoop;
	public static void main(String[] args) throws Exception{
		Runnable demoThread1 = new DemoThread("asd", 1000000);
		Runnable demoThread2 = new DemoThread("zxc", 50);
		Runnable demoThread3 = new DemoThread("Thread 2: ", 10);
		Thread th1 = new Thread(demoThread1);
		Thread th2 = new Thread(demoThread2);
		Thread th3 = new Thread(demoThread3);
//		th1.setPriority(Thread.MAX_PRIORITY);
		System.out.println("Thread ID: " + th1.getId());
		System.out.println("Thread name: " + th1.getName());
		System.out.println("Thread Priority: " + th1.getPriority());
		System.out.println("Thread state: " + th1.getState());
		th1.start();
		
		System.out.println("Thread ID: " + th2.getId());
		System.out.println("Thread name: " + th2.getName());
		System.out.println("Thread Priority: " + th2.getPriority());
		System.out.println("Thread state: " + th2.getState());
//		th1.join();
		th2.start();
	}
	
	public DemoThread(String name, int sizeLoop){
		this.threadName = name;
		this.sizeLoop = sizeLoop;
	}
	@Override
	public void run() {
		for (int i = 0; i < sizeLoop; i++) {
			System.out.println(threadName + i);
			if (threadName.equals("asd") && i == 0)
				try {
					Thread.sleep(1000);
				} catch (Exception e) {
					e.printStackTrace();
				}
		}
	}
}
